import { observable, action } from 'mobx';
import { Tools, Toast } from 'weaver-mobile';
import { ListAdvanced ,Browser} from 'weaver-mobile-page';
import * as Apis from "../../apis/docLedgerApi/recDocDetailApi";

const { getLabel } = Tools;

class RecDocDetailStore{
  @observable listAd = new ListAdvanced.Store({ route: '/docLedger/recDocDetail', id: 'demo0' });
  @observable browser = new Browser.Store({ route: '/docLedger/recDocDetail', id: 'search-history' });
  @observable browserValue = [];
  @observable identifier = "";
  @observable resendDocId = "";
  @observable receiveComanyId = ""; 
  @observable showCheck = false;
  @observable popoverVisible = false;


  @action.bound 
  getData(entityName=""){
    const params ={
      entityName:entityName,
      documentId:this.identifier,
      // documentId:"69e8720c-09ec-41d1-84a9-ecb6f5eece97",

    }
    this.listAd.listViewStore.clearData();
    this.getListData({ url: '/api/offical/sendDoc/getWebAddresseeList',method:"POST",params:params });
  }

  @action.bound 
  setShowCheck(){
    this.showCheck = !this.showCheck;
  }

  @action.bound 
  setIdentifier(identifier){
    this.identifier = identifier;
  }

  @action.bound 
  setPopoverVisible(bool){
    this.popoverVisible = bool;
  }

  @action.bound 
  setResendDocId(resendDocId){
    this.resendDocId = resendDocId;
  }

  @action.bound 
  setReceiveCompanyId(receiveComanyId){
    this.receiveComanyId = receiveComanyId;
  }

  @action.bound
  repeal(text,companyId){
    const params={
      ids:companyId,
      receiverDepartments:this.receiveComanyId,
      status:"4",
      detail:text,//处理意见
    }
    Apis.revokedDoc(params).then(data=>{
      if(data.api_status){
        this.getData();
        Toast.success(data.api_message, 1)
      }else{
        Toast.fail(data.api_message, 1);
        
      }
    })
  }

  @action.bound 
  resend(ids){
    const params={
      receiverDepartments:ids,
      ids:this.resendDocId,
      status:"0",
    }
    Apis.resendDoc(params).then(data=>{
      if(data.api_status){
        this.getData();
        Toast.success(getLabel("27564","发送成功"),1)
      }else{
        Toast.fail(data.api_message, 1);
      }
      
    })
  }


  getListData = (params = { url: '', params: {} }) => {
    try {
      Tools.callApi({
        ...params,
        params: {
          ...params.params,
        },
      }).then(action((res) => {
        const dataKey = res[this.responseKey] || res.datas || res.sessionkey;
        this.listAd.listViewStore.getData({ dataKey },undefined,true);
      }));
    } catch (e) {
      Toast.info(e, 1);
    }
    return this;
  }

}

export default RecDocDetailStore;